HttpWatch Automation Reference - Version 15.x
Using HttpWatch Automation with C# / C# - Recording with HttpWatch
In This Topic
    C# - Recording with HttpWatch
    In This Topic

    First, your application needs to create an instance of Chrome or Edge using the HttpWatch extension, as explained in the C# - Overview topic. Having done this, your application will contain references to Controller and Plugin objects.

    The following discussion assumes that these object references are called control and extension, respectively.

    Filter Control

    Before starting recording, you should decide whether to enable or disable HttpWatch filtering. The automation interface only allows you to enable or disable an existing filter. The filtering criteria itself can only be set up manually through the HttpWatch extension user interface.

    If you do not want specifically to use a filter it is best to disable filtering in your application, as follows:

    Turn Off Filtering
    Copy Code
    plugin.Log.EnableFilter(false);
    

     

    Alternatively to enable filtering, make the same call, but with the parameter set to  true.

    Clearing the HttpWatch Log and the Browser Cache

    To make sure that you don't pick up traffic that was previously recorded in HttpWatch by user or another automation program you should clear the Log object that is associate with the Plugin. This can be done with the Plugin object's Clear method:

     

    Clear the HttpWatch Log
    Copy Code
    plugin.Clear();
    

     

    It may also be necessary to put the browser into a known state at the start of your test. Often this is achieved by clearing the browser cache and cookie database to emulate the state of the browser when a new visitor opens a web page. The extension object provides two methods, ClearCache and ClearAllCookies to perform these tasks.

    Starting Recording

    To activate traffic logging call the Plugin object's Record method:

    Start Recording
    Copy Code
    plugin.Record();
    

    Generating HTTP Traffic to Record

    Of course, nothing will be recorded by HttpWatch until the browser starts to access and interact with web pages.

    In an automation program there are three ways to drive the browser:

    1.    
    2. Use a framework that has been designed to drive browser interactions, e.g. Selenium
    3. Use the Plugin object's GotoURL method

    Option 2) doesn't is not as powerful or flexible as the other two alternatives but it provides a simple way to test that pages load correctly and to measure their performance.

    The GotoURL methods returns immediate without waiting for the page to load. Normally, you would want to wait for the page to load so that you could look at the traffic that it generated or the performance timings gathered by HttpWatch. The way to do this is to call the Controller object's Wait methods passing the Plugin object reference and a timeout value in seconds (-1 is used to wait forever):

     

    Loading a Page using HttpWatch
    Copy Code
    string myUrl = http://www.example.com;
    plugin.GotoUrl( myUrl );
    control.Wait( plugin, -1 /* don't return until the page loads */ );
    

     

    For more information about how the page load is detected please see the documentation for the IsLoadingPage property and the Wait method.

    Stopping Recording

    When you wish to stop recording HTTP traffic call the Plugin object's Stop method:

    Closing the Browser

    At the end of your application, or earlier, if appropriate, you should close the browser, by calling the Plugin object's CloseBrowser method:

     

    See Also